<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/2/19 0019
 * Time: 15:56
 */

namespace singleton;

class Singleton
{

    //自身实例
    public static $_instance;

    public function __construct()
    {

    }

    //禁止clone对象
    public function __clone()
    {
        echo 'clone is forbidden';
    }

    //得到实例
    public static function getInstance()
    {
        //instanceof 判断一个对象是否是某个类的实例
        if (!self::$_instance instanceof self) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    //测试方法
    public function test()
    {
        echo "这是个测试 \n";
    }
}